<template>
  <div class="vm-lock-screen vm-panel">
    <div class="company">
      <img src="../assets/logo.png" height="200" style="margin: -50px">
    </div>
    <div class="user">
      <p class="name">{{ loginForm.user_name }}</p>
    </div>
    <Input :maxlength="8" v-model="loginForm.pass_word" placeholder="Please enter password" type="password" :style="{ width: 300 + 'px' }"></Input>
    <Button type="primary" @click="login()">Enter</Button>
  </div>
</template>
<script>
export default {
  name: 'VmLockScreen',
  data: function () {
    return {
      loginForm:{
        user_name:"",
        pass_word:"",
      }
    }
  },
  methods: {
    login() {
      const _this = this;
      this.axios.post(_this.API.http_login + 'login', _this.loginForm).then(function (resp) {
            if (resp.data) {
              const respData = JSON.parse(JSON.stringify(resp.data))
              if (respData.code === 200) {
                localStorage.setItem("user_name",_this.loginForm.user_name)
                localStorage.setItem("token",respData.data)
                localStorage.setItem("isLogin", "true")
                _this.CONST.isLogin = true
                _this.$router.push("/")
              } else {
                _this.FUN.errorMessage(_this,respData.message);
              }
            } else {
              return false;
            }
          }
      );
    }
  },
  created() {
    this.loginForm.user_name = localStorage.getItem("user_name")
    if (this.loginForm.user_name === null){
      this.$router.push("login")
    }
  }
}
</script>
